package StudyCode.summary.mycollection;

import java.util.Collection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertsCollectionToArrayOfStrings {
	public static void main(String[] argv) {
		Collection collection = java.util.Arrays.asList("科技与人文(",
				"www.tah1986.com");
		System.out.println(java.util.Arrays
				.toString(toStringArray(collection)));
	}

	public static String[] toStringArray(Collection collection) {
		if (collection == null) {
			return null;
		}
		if (collection.isEmpty()) {
			return new String[]{};
		}
		int index = 0;
		String[] result = new String[collection.size()];
		for (Object item : collection) {
			if (item == null) {
				result[index++] = null;
			}
			result[index++] = String.valueOf(item);
		}
		return result;
	}
}
